<?php

namespace app\admin\controller\game;

use app\common\controller\Backend;
use think\Db;

/**
 * 充值历史
 *
 * @icon fa fa-circle-o
 */
class Tixian extends Backend
{
    
    /**
     * Tixian模型对象rpint
     * @var \app\admin\model\game\Tixian
     */
    protected $model = null;
    protected $noNeedRight = ['start', 'pause', 'change', 'detail', 'cxselect', 'searchlist' ,'index'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\game\Tixian;

    }
    public function repay()
    {
        //print_r($this->request->param());
        $ids=$this->request->param('ids');
 
        $url=Db::name('user_tixian')->where('id='.$ids)->value('payurl');
        $dat=$this->http_get($url);
        $data=json_decode($dat,true);
        
        if (!empty($data['payment_no'])) {
           Db::name('user_tixian')->where('id='.$ids)->setfield('paymentno',$data['payment_no']);
           echo "取款ok";
        }else{
            print_r($data);
        }
      
    }
        public function repoint()
    {
        //print_r($this->request->param());
        $ids=$this->request->param('ids');
        $where['id']=$ids;
        $where['paymentno']=array('eq','');
        $point=Db::name('user_tixian')->where($where)->value('point');
       if ($point>0) {
       	$uid=Db::name('user_tixian')->where($where)->value('uid');
       	Db::name('user')->where('id='.$uid)->setInc('points',$point);
        Db::name('user_tixian')->where($where)->delete();
           echo "恢复ok";
        }else{
            echo "恢复失败";
        }
      
    }
    private function http_get($url){//带json发送，无json数据

        $ch = curl_init();  
        curl_setopt($ch, CURLOPT_URL,$url);  
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
        $result = curl_exec($ch);  
        curl_close($ch);  
        return $result;
        }   
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    

}
